import { maccApi, requestHttp } from '@utils/index';
// import { i18nRender } from '@/locales';
const state = {
  twillio: null, //网络下的所有vlan
  portals: [],
  radiusServer: []
};

const mutations = {
  SET_TWILLIO(state, payload) {
    state.twillio = payload;
  },

  SET_PORTALS(state, payload) {
    state.portals = payload;
  },

  CLEAR_PORTAL_AUTH_STATE(state) {
    state.twillio = null;
  },
  // 获取服务器列表
  SET_SERVER_GRP_CONF(state, payload) {
    state.radiusServer = payload;
  },

  CLEAR_PORTAL_SERVER_STATE(state) {
    state.radiusServer = null;
  },
};

const actions = {
  async getTwillio({ commit }, params) {
    const { tenantName, tenantId } = params;
    const { nbr_intf } = state;
    var data = {
      api: maccApi.GET_BAAS_DETAIL.replace('{tenantName}', tenantName).replace(
        '{tenantId}',
        tenantId
      ),
      method: 'GET',
    };
    let { code, msg, smsSid, smsToken, smsFromPhoneNumber } = await requestHttp(
      data
    );
    const twillio = {};
    if (code == 0) {
      twillio.sid = smsSid;
      twillio.authToken = smsToken;
      twillio.authPhone = smsFromPhoneNumber;
    }

    commit('SET_TWILLIO', twillio);
    return { code, msg };
  },
  async getRadiusServer({ commit }, sn) {
    let { code, data, msg } = await requestHttp({
      api: maccApi.PORTAL_SERVER_GET_LIST_API,
      method: 'GET',
      replaces: {
        sn: sn,
      },
    });
    let radiusServer = null;
    if (code == 0) {
      radiusServer = data;
    }

    commit('SET_SERVER_GRP_CONF', radiusServer);
    return { code, msg };
  },
};

const getters = {};

export default {
  namespaced: true, //开启命名空间，更好的区分使用stage,防止不同stage模块中的方法重名
  state,
  getters,
  mutations,
  actions,
};
